package cn.parus.commons.common.Log.Filter;

import cn.parus.commons.common.Log.utils.ServerWebExchangeContext;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;

/**
 * @Title: WebFilter
 * @Author 潘春兰
 * @Package cn.parus.commons.common.Log.Filter
 * @Date 2025/4/1 23:22
 * @description: TODO 获取请求信息
 * TODO 在后续处理中可以通过ServerWebExchangeContext获取当前请求的exchange对象
 * @Version:
 */
@Configuration
public class RequestContextFilter implements WebFilter {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
        return chain.filter(exchange)
                .contextWrite(ctx -> ctx.put(
                        ServerWebExchangeContext.SERVER_WEB_EXCHANGE_CONTEXT_KEY,
                        exchange
                ));
    }
}
